<template>
	<view>
		<view class="exam-box">
			<view class="exam-item" v-for="(item, index) in sourceData" :key="index">
				<view class="exam-left">
					<view class="exam-icon flex-1">
						<image :src="`/static/${item.userType == '0'?'sp':'cs'}.png`" mode="widthFix"></image>
					</view>
					<view class="exam-line flex-1" v-if="index != sourceData.length - 1">
						<view class="line-item"></view>
					</view>
				</view>
				<view class="exam-right">
					<view class="exam-type">{{item.userType | toName}}</view>
					<view class="exam-content">
						<view class="exam-content-item" v-for="(items, idx) in item.children">
							<view class="exam-info">
								<view class="exam-avatar">
									<image :src="items.avatar" mode="aspectFill"></image>
								</view>
								<view class="exam-name">{{items.name}}</view>
							</view>
						</view>
						<view v-if="item.userType == 1" class="add-btn flex-1">+</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "approvalTree",
		props: {
			sourceData: {
				type: Array,
				default: () => ([])
			}
		},
		data() {
			return {

			};
		},
		methods: {

		},
		filters: {
			toName(e) {
				let name = ''
				if (e == '0') {
					name = '审批人'
				} else if (e == '1') {
					name = '抄送人'
				}
				return name
			}
		}
	}
</script>

<style lang="scss">
	.flex-1 {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.exam-box {
		.exam-item {
			display: flex;

			.exam-left {
				.exam-icon {
					width: 30px;
					height: 30px;
					border-radius: 50%;
					background: #007AFF15;

					image {
						width: 80%;
					}
				}

				.exam-line {
					width: 30px;
					height: calc(100% - 30px);

					.line-item {
						width: 5rpx;
						height: 100%;
						background-color: #007AFF80;
					}

				}
			}

			.exam-right {
				margin-left: 10px;
				flex: 1;

				.exam-type {
					line-height: 30px;
					color: #888;
				}



				.exam-content {
					display: flex;
					margin: 10px 0;
					flex-wrap: wrap;

					.exam-content-item {
						margin: 0 10px 10px 0;

						.exam-avatar {
							width: 40px;
							height: 40px;

							image {
								border-radius: 5px;
								width: 100%;
								height: 100%;
							}
						}

						.exam-name {
							font-size: 12px;
							color: #999;
							margin-top: 10rpx;
							text-align: center;
						}
					}

					.add-btn {
						width: 40px;
						height: 40px;
						border-radius: 5px;
						background-color: #F5F6F8;
						border: 1px solid #EEE;
						color: #888;
						font-size: 18px;
					}
				}
			}
		}
	}
</style>